package plugin

import "fmt"

type Plugin_RpcServer struct {
	// 具体的实现
	Impl Plugin_Interface
}

func (s *Plugin_RpcServer) SetParam(arg interface{}, resp *string) error {
	arReq, ok := arg.([]string)
	if !ok {
		return fmt.Errorf("参数解析异常, %v", arg)
	}
	*resp = s.Impl.SetParam(arReq[0], arReq[1], arReq[2], arReq[3])
	return nil
}

// -------------------- RPC 服务外部接口 --------------
func (s *Plugin_RpcServer) GetChannels(args interface{}, resp *string) error {
	*resp = s.Impl.GetChannels()
	return nil
}

func (s *Plugin_RpcServer) GetSummaryInfo(args interface{}, resp *string) error {
	ss, ok := args.([]byte)
	if !ok {
		return fmt.Errorf("参数解析异常, %v", args)
	}
	b := s.Impl.GetSummaryInfo(ss)
	*resp = string(b)
	return nil
}

func (s *Plugin_RpcServer) GetBlockInfo(args interface{}, resp *string) error {
	ss, ok := args.([]byte)
	if !ok {
		return fmt.Errorf("参数解析异常, %v", args)
	}
	*resp = s.Impl.GetBlockInfo(ss)
	return nil
}

func (s *Plugin_RpcServer) GetTransactionInfo(args interface{}, resp *string) error {
	ss, ok := args.([]byte)
	if !ok {
		return fmt.Errorf("参数解析异常, %v", args)
	}
	b := s.Impl.GetTransactionInfo(ss)
	*resp = string(b)
	return nil
}
